package com.cy.study.util;

import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

/**
 * 缓存类 没有redis的时候先用一下缓存代替测试
 * @version v1.0.0
 * @explain
 * @date 2024/3/18 11:07
 */
@Component
public class CacheTool {

    private Map<String, String> cache = new HashMap<>();

    {
        cache.put("token:12345678","eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE3MTQ0NzAxNDM1LCJ1c2VySWQiOjEyMzQ1Njc4fQ._wWsYcfn8Lke29nTD5-_auOHgezYpyxxiKcOz28Mk1k");
        cache.put("token:27","eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE3MTQ0NTk2MDYyLCJ1c2VySWQiOjI3fQ.Qo3wyvrSTbysKPvKaqczbyM0WwMjBNl38Gk0HIEu_Ko");
    }

    /**
     * 是否包含某个key
     * @param key
     * @return
     */
    public Boolean containsKey(String key){
        return cache.containsKey(key);
    }

    public void add(String key,String value){
        cache.put(key, value);
    }

    public String get(String key){
        String o = cache.get(key);
        return o;
    }

    public static void main(String[] args) {
        Map<String,String> map = new HashMap<>();
        map.put("12345","678910");
        System.out.println(map.containsKey("12345"));
    }


}
